package com.jelly.web.modules.basics.bulletin.service.impl;

import com.jelly.common.constant.BulletinConstant;
import com.jelly.common.constant.Constant;
import com.jelly.common.util.StringUtils;
import com.jelly.web.modules.basics.bulletin.dao.BulletinAndUserMapper;
import com.jelly.web.modules.basics.bulletin.domain.BulletinAndUser;
import com.jelly.web.modules.basics.bulletin.domain.BulletinAndUserExample;
import com.jelly.web.modules.basics.bulletin.service.IBulletinAndUserService;
import com.jelly.web.modules.basics.bulletin.service.IBulletinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @创建人 ql
 * @创建时间 2018-09-29 14:15
 * @项目名称 jelly
 * @功能描述: 公告用户扩展接口实现类
 **/
@Service
public class BulletinAndUserServiceImpl implements IBulletinAndUserService {

    @Autowired
    private BulletinAndUserMapper bulletinAndUserMapper;

    @Autowired
    private IBulletinService bulletinService;

    /**
     * 条件获取信息
     * @param bulletinAndUser
     * @return
     */
    @Override
    public List<BulletinAndUser> getBulletinAndUser(BulletinAndUser bulletinAndUser) {

        BulletinAndUserExample example = new BulletinAndUserExample();

        BulletinAndUserExample.Criteria criteria = example.createCriteria();


        if(StringUtils.isNotBlank(bulletinAndUser.getTitle())){

            criteria.andTitleEqualTo(bulletinAndUser.getTitle());

        }

        if(StringUtils.isNotBlank(bulletinAndUser.getIsState())){

            criteria.andIsStateEqualTo(bulletinAndUser.getIsState());

        }

        if(StringUtils.isNotBlank(bulletinAndUser.getIsSetTop())){

            criteria.andIsSetTopEqualTo(bulletinAndUser.getIsSetTop());

        }

        if(StringUtils.isNotBlank(bulletinAndUser.getNickname())){

            criteria.andNickNameEqualTo(bulletinAndUser.getNickname());

        }

        if(StringUtils.isNotBlank(bulletinAndUser.getType())){

            criteria.andTypeEqualTo(bulletinAndUser.getType());

        }

        example.setOrderByClause("`is_set_top` = 'INTHEYOP' DESC,`sort` ASC");

        return bulletinAndUserMapper.selectByExampleWithBLOBs(example);

    }

    /**
     * 条件获取信息
     * @return
     */
    @Override
    public List<BulletinAndUser> getBulletinAndUserAll(String type) {

        BulletinAndUserExample example = new BulletinAndUserExample();

        BulletinAndUserExample.Criteria criteria = example.createCriteria();

        criteria.andIsSetTopEqualTo(BulletinConstant.INTHEYOP);

        criteria.andIsStateEqualTo(Constant.SUCCESS);

        if(StringUtils.isNotBlank(type)){
            criteria.andTypeEqualTo(type);
        }

        example.setOrderByClause("`sort` ASC");

        return bulletinAndUserMapper.selectByExampleWithBLOBs(example);

    }

    /**
     * 主键获取信息
     * @param bulletinId
     * @return
     */
    @Override
    public BulletinAndUser getBulletinAndUser(String bulletinId) {

        return bulletinAndUserMapper.selectByPrimaryKey(bulletinId);

    }

}
